package com.example.trafficsystem.entity;

import com.example.trafficsystem.entity.Exam;
import com.example.trafficsystem.entity.ExamAnswer;
import com.example.trafficsystem.entity.Student;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExamRecord {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne
    private Exam exam;  // 关联到考试

    @ManyToOne
    private Student student;  // 关联到学员

    private LocalDateTime startTime;  // 开始时间
    private LocalDateTime submitTime;  // 提交时间
    private Integer score;  // 学员得分
    private String evaluation;  // 对考核的评价
    private Boolean isSubmitted;  // 是否已提交

    @JsonManagedReference  // 让 ExamRecord 反向引用 ExamAnswer 时避免无限递归
    @OneToMany(mappedBy = "examRecord", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<ExamAnswer> answers;  // 学员的答题记录
}
